MPT.addAction("register", function(_elm) {

    var form_jQ = jQuery(_elm);
    var submit_jQ = jQuery('.e_submit', _elm);
    var account_jQ = jQuery('.e_account', _elm);
    var nickname_jQ = jQuery('.e_nickname', _elm);
    var pwd_1_jQ = jQuery('.e_pwd', _elm);
    var pwd_2_jQ = jQuery('.e_pwd2', _elm);
    var idcard_jQ = jQuery('.e_idcard', _elm);
    var realname_jQ = jQuery('.e_realname', _elm);
    var mail_jQ = jQuery('.e_email', _elm);
    var auth_input_jQ = jQuery('.e_randcode', _elm);
    var auth_img_jQ = jQuery('.e_rand_img', _elm);
    var auth_change_jQ = jQuery('.e_rand_change', _elm);
    var shint_jQ = jQuery('.e_shint', _elm);
    var s1_jQ = jQuery('.e_s1', _elm);
    var s2_jQ = jQuery('.e_s2', _elm);
    var s3_jQ = jQuery('.e_s3', _elm);
    var agree_jQ = jQuery('.e_agree', _elm);
    var strength_jQ = jQuery('.e_strength', _elm);

    var hints = { 'account': {}, 'nickname': {}, 'pwd': {}, 'pwd2': {}, 'realname': {}, "idcard": {}, "idcard_js": {}, "email": {}, "randcode": {}, "remote": {} };
    hints['account'][-1] = "请输入6-16位小写字母或数字,首位为字母";
    hints['account'][-2] = "请输入账号";
    hints['account'][-5] = "此帐号已经被使用";
    hints['nickname'][-1] = "昵称最长为12个字符，可由中英文数字组成";
    hints['nickname'][-2] = "请输入昵称";
    hints['nickname'][-5] = "此昵称已被使用";
    hints['pwd'][-1] = "8-16位，字母区分大小写";
    hints['pwd'][-2] = "请输入密码";
    hints['pwd2'][0] = "两次输入密码不一样";
    hints['pwd2'][-2] = "请再次输入您的密码";
    hints['realname'][-1] = "真实姓名只能为汉字";
    hints['realname'][-2] = "请输入真实姓名";
    hints['idcard'][-1] = "身份证号不正确";
    hints['idcard'][-2] = "请输入身份证号";
    hints['idcard_js'][-1] = "判断帐号归属依据，注册后不能修改";
    hints['idcard_js'][-2] = "身份证号只有15位或18位！";
    hints['idcard_js'][-3] = "身份证除最后一位外，必须为数字！";
    hints['idcard_js'][-4] = "身份证输入错误，请重试！";
    hints['idcard_js'][-5] = "身份证输入错误，请重试！";
    hints['idcard_js'][-6] = "您属于未满18周岁未成年人，无法注册";
    hints['email'][-1] = "安全邮箱不符合规则";
    hints['email'][-2] = "请输入安全邮箱";
    hints['remote'][-8] = "注册失败";
    hints['randcode'][-99] = "验证码错误";

    auth_img_jQ.attr('src', "/authimg?type=reg&t=" + Math.random());

    var doRegister = function() {

        if (!agree_jQ.find('input').is(':checked')) {
            agree_jQ.find('.e_hint').show();
        } else {
            agree_jQ.find('.e_hint').hide();

            jQuery.ajax({
                type: "POST",
                url: MPT.Config["interface"]["register"],
                data: { "account": account_jQ.val(),
                    "email": mail_jQ.val(),
                    "idCard": idcard_jQ.val(),
                    "nickname": nickname_jQ.val(),
                    "pwd": pwd_1_jQ.val(),
                    "pwd2": pwd_2_jQ.val(),
                    "randCode": auth_input_jQ.val(),
                    "realName": realname_jQ.val(),
                    "targetId": 0
                },
                dataType: 'json',
                success: function(_resp) {                   
                    
                    if (_resp['result'] == 1) {
                        window.location.href = MPT.Config["url"]["guide_info"];
                    }
                    if (_resp['result'] == -99) {

                        $.each(_resp['data'], function(_k, _d) {

                            var key = _k.toLowerCase();
                            var resultID = _resp['data'][_k];

                            //密码部分较特殊，单独处理
                            if (key == 'pwd') {
                                if (resultID != 1) {
                                    strength_jQ.hide();
                                    $('.e_' + key).nextAll('.e_hint').removeClass('reg_ok reg_ts').addClass('reg_no').html(hints[key][resultID]).show();
                                }
                            } else {
                                if (resultID == 1) {
                                    $('.e_' + key).nextAll('.e_hint').removeClass('reg_no reg_ts').addClass('reg_ok').html('').show();
                                } else {
                                    $('.e_' + key).nextAll('.e_hint').removeClass('reg_ok reg_ts').addClass('reg_no').html(hints[key][resultID]).show();
                                }
                            }
                        });
                    }
                }
            });
        }
    };


    account_jQ.blur(function() {

        jQuery.get('/auth/checkAccount?account=' + jQuery(this).val(), function(_resp) {

            var resultID = _resp['result'];
            if (resultID < 0) {
                account_jQ.next('.e_hint').removeClass('reg_ok reg_ts').addClass('reg_no').html(hints['account'][resultID]);
            }
            if (resultID == 1) {
                account_jQ.next('.e_hint').removeClass('reg_no reg_ts').addClass('reg_ok').html('');
            }
        });
    });

    nickname_jQ.blur(function() {

        jQuery.get('/auth/checkNickName?nickname=' + jQuery(this).val(), function(_resp) {

            var resultID = _resp['result'];
            if (resultID < 0) {
                nickname_jQ.next('.e_hint').removeClass('reg_ok reg_ts').addClass('reg_no').html(hints['nickname'][resultID]);
            }
            if (resultID == 1) {
                nickname_jQ.next('.e_hint').removeClass('reg_no reg_ts').addClass('reg_ok').html('');
            }
        });
    });


    pwd_1_jQ.bind('keydown focus', function() {

        strength_jQ.show();
        pwd_1_jQ.next('.e_hint').hide();
    });


    pwd_1_jQ.bind('keyup blur', function() {

        pwd = $(this).val();
        if (!pwd) {
            strength_jQ.find('span').removeClass('active').addClass('no_active');
            shint_jQ.html('8-16位，字母区分大小写');
        } else {
            S_level = Verifier.PWDStrong(pwd);
            switch (S_level) {
                case 0:
                    strength_jQ.find('span').removeClass('active').addClass('no_active');
                case 1:
                    s1_jQ.removeClass('no_active').addClass('active');
                    s2_jQ.removeClass('active').addClass('no_active');
                    s3_jQ.removeClass('active').addClass('no_active');
                    shint_jQ.html('弱：试试标点、数字、字母混搭');
                    break;
                case 2:
                    s1_jQ.removeClass('no_active').addClass('active');
                    s2_jQ.removeClass('no_active').addClass('active');
                    s3_jQ.removeClass('active').addClass('no_active');
                    shint_jQ.html('中：试试标点、数字、字母混搭');
                    break;
                default:
                    s1_jQ.removeClass('no_active').addClass('active');
                    s2_jQ.removeClass('no_active').addClass('active');
                    s3_jQ.removeClass('no_active').addClass('active');
                    shint_jQ.html('强');
                    break;
            }
        }
    });


    pwd_2_jQ.blur(function() {
        pwd_2_jQ.next('.e_hint').show();

        if (!pwd_2_jQ.val()) {
            pwd_2_jQ.next('.e_hint').removeClass('reg_ok reg_ts').addClass('reg_no').html(hints['pwd2'][-2]);
        } else {
            if (pwd_1_jQ.val() != pwd_2_jQ.val()) {
                pwd_2_jQ.next('.e_hint').removeClass('reg_ok reg_ts').addClass('reg_no').html(hints['pwd2'][-1]);
            } else {
                pwd_2_jQ.next('.e_hint').removeClass('reg_no reg_ts').addClass('reg_ok').html('');
            }
        }
    });

    realname_jQ.blur(function() {

        var realName = jQuery(this).val();

        if (realName == "" || realName.length < 2 || realName.length > 4) {
            realname_jQ.next('.e_hint').removeClass('reg_ok reg_ts').addClass('reg_no').html(hints['realname'][-2]);
        }
        else if (!realName.match(/^[\u4e00-\u9fa5]+$/)) {
            realname_jQ.next('.e_hint').removeClass('reg_ok reg_ts').addClass('reg_no').html(hints['realname'][-1]);
        }
        else {
            realname_jQ.next('.e_hint').removeClass('reg_no reg_ts').addClass('reg_ok').html('');
        }
    });

    idcard_jQ.blur(function() {

        var result = Verifier.isCardID(jQuery(this).val());

        if (result != 1) {
            idcard_jQ.next('.e_hint').removeClass('reg_ok reg_ts').addClass('reg_no').html(hints['idcard_js'][verify_result]);
        } else {
            idcard_jQ.next('.e_hint').removeClass('reg_no reg_ts').addClass('reg_ok').html('');
        }
    });

    mail_jQ.blur(function() {

        var email = jQuery(this).val();
        if (email == "") {
            mail_jQ.next('.e_hint').removeClass('reg_ok reg_ts').addClass('reg_no').html(hints['email'][-2]);
        }
        else if (!email.match(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/)) {
            mail_jQ.next('.e_hint').removeClass('reg_ok reg_ts').addClass('reg_no').html(hints['email'][-1]);
        }
        else {
            mail_jQ.next('.e_hint').removeClass('reg_no reg_ts').addClass('reg_ok').html('');
        }
    });

    auth_input_jQ.focus(function() {
        auth_input_jQ.nextAll('.e_hint').hide();
    });

    auth_change_jQ.click(function() {
        auth_img_jQ.attr('src', "/authimg?type=reg&t=" + Math.random());
    });

    submit_jQ.click(function() {
        doRegister();
    });

    Util.KeyBoardMonitor(form_jQ, 13, function() { doRegister(); });

});